package logic

import (
	"1-8zy/rpc/internal/svc"
	"1-8zy/rpc/model/mysql"
	"1-8zy/rpc/shop"
	"context"
	"fmt"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserListLogic {
	return &UserListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserListLogic) UserList(in *shop.UserListRequest) (*shop.UserListResponse, error) {
	// todo: add your logic here and delete this line
	u := mysql.User{}
	user, err := u.GetUser(int(in.Page), int(in.PageSize), int(in.Status))
	if err != nil {
		return nil, fmt.Errorf("查询失败")
	}
	fmt.Println(user)
	var list []*shop.UserList
	for _, u2 := range user {
		list = append(list, &shop.UserList{
			Phone:    u2.Phone,
			Password: u2.Password,
			Status:   int64(u2.Status),
		})
	}
	fmt.Println(list)
	return &shop.UserListResponse{
		User: list,
	}, nil
}
